<?php


namespace app\index\controller;

class CardApp extends \app\common\Controller
{
	public function CardQuery($appid)
	{
		$get = $this->request->get();
		$post = $this->request->post();
		if (isset($get["submit"]) && isset($post["list"]) && isset($post["code"])) {
			if (captcha_check($post["code"], "CardAppPublic")) {
				if (count(explode("\r\n", $post["list"])) >= 3000) {
					return "<script>alert('查询数量过多>3000');location.href='./'</script>";
				}
				$data = [];
				foreach (explode("\r\n", $post["list"]) as $item) {
					$card = findCardCaseSensitive("app_card_user", ["appid" => $appid, "card" => $item]);
					if (empty($card)) {
						$result = "<font color='blue'>不存在</font>";
					} else {
						if ($card["status"] == 0) {
							$result = "<font color='black'>未使用,时长:{$card["time_value"]}" . \app\common\model\CardTimeType::getName($card["time_type"]) . "</font>";
						} else {
							if ($card["endtime"] >= time()) {
								$result = "<font color='#deb887'>已使用,到期:" . date("Y-m-d H:i:s", $card["endtime"]) . "</font>";
							} else {
								$result = "<font color='red'>已到期</font>";
							}
						}
					}
					$data[$item] = $result;
					$this->assign("data", $data);
				}
			} else {
				return "<script>alert('验证码错误');location.href='./'</script>";
			}
		}
		return $this->fetch("./view/CardAppQuery.html");
	}
	public function code()
	{
		$id = "CardAppPublic";
		$config = ["fontSize" => 40, "length" => 4, "useNoise" => true, "reset" => true, "useCurve" => true];
		$captcha = new \think\captcha\Captcha($config);
		return $captcha->entry($id);
	}
}